// 点击注册按钮，将注册信息发送至后端

const button = document.querySelector(".button");
const username = document.querySelector(".username input");
const password = document.querySelector(".password input");
// console.log(username,password)


button.onclick = function(){

    ajaxPost("http://localhost:3000/api",res=>{
        console.log(res)
        res=JSON.parse(res);
        if(res.code===0){
            alert("用户名重复");
            username.value="";
            username.focus();
        }else{
            if(confirm("注册成功，是否跳转到登录")){
                location.href = "./login.html"
            }
        }
    },
    {
        type:"register",
        username:username.value,
        password:password.value,

    })
}